package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.GetCommentDetailBean;
import cn.bocweb.spinning.view.common.GlideCircle;
import cn.bocweb.spinning.view.common.MyAdapter;

/**
 * Created by chenchangxing on 15/12/26.
 */
public class InfoAllCommentAdapter extends MyAdapter<GetCommentDetailBean.DataEntity> {

    public InfoAllCommentAdapter(Context context, List<GetCommentDetailBean.DataEntity> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_info_all_comment, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String nickname = list.get(position).getNickname();
        if (!(nickname == null || nickname.isEmpty())) {
            holder.allCommentNickname.setText(list.get(position).getNickname());
        } else {
            holder.allCommentNickname.setText("未命名用户");
        }
        if (!(list.get(position).getUthumb() == null || list.get(position).getUthumb().isEmpty())) {
            Glide.with(context).load(list.get(position).getUthumb()).transform(new GlideCircle(context)).into(holder.allCommentIcon);
        } else {
            holder.allCommentIcon.setImageResource(R.mipmap.drawer_icon_unlogin);
        }
        holder.allCommentContent.setText(list.get(position).getContent());
        holder.allCommentTime.setText(list.get(position).getTime());

        return convertView;
    }


    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'item_info_all_comment.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.all_comment_icon)
        ImageView allCommentIcon;
        @Bind(R.id.all_comment_nickname)
        TextView allCommentNickname;
        @Bind(R.id.all_comment_time)
        TextView allCommentTime;
        @Bind(R.id.all_comment_content)
        TextView allCommentContent;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
